package com.example.demo.Controller;

import com.example.demo.Entity.FriendChart;
import com.example.demo.Entity.User;
import com.example.demo.Service.FriendChartService;
import jakarta.servlet.ServletOutputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/friendchart")
public class FriendChartController {
    @Autowired
    private FriendChartService friendChartService;

    @PostMapping("/Insert")
    public void setFriendChatService(@RequestBody FriendChart friendChart){
        friendChartService.insertFriendChart(friendChart);
    }
    @GetMapping("/FindAll/{selfId}")
    public List<Integer> findALL(@PathVariable Integer selfId){
      return  friendChartService.findAll(selfId);
    }
    @GetMapping("/Delete")
    public void deleteFriendChat(@RequestParam Integer selfId,@RequestParam Integer friendId){
        friendChartService.deleteFriendChart(selfId,friendId);
    }

    @GetMapping("/findfriends")
    public List<User> findUser(@RequestParam Integer selfId){
        System.out.println(selfId);
        System.out.println("-------------------------");
        return friendChartService.finduserTotal(selfId);
    }

    @PostMapping("/AddFriend")
    public void AddFriend(@RequestBody User u1, @RequestBody User u2){
        friendChartService.AddFriend(u1.getId(),u2.getUsername());
    }

    @GetMapping("/checkout")
    public boolean checkout(@RequestParam Integer selfId,@RequestParam Integer friendId){
        return friendChartService.checkout(selfId,friendId);
    }
}
